//
//  FlyMainTabBarViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/9/4.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "FlyMainTabBarViewController.h"
#import "EJSUserModel.h"
#import "EJSShoppingCartViewController.h"
#import "EJSLoginViewController.h"

#if (YiPinShangCheng == 1)//一品商城
#import "XMMovableButton.h"
#import "CustomerServiceViewController.h"
#endif


@interface FlyMainTabBarViewController ()<UITabBarControllerDelegate>{

}

@end

@implementation FlyMainTabBarViewController

+ (void)initialize {
    // 设置全局tabBar文字颜色
    UITabBarItem * tabBarItem = [UITabBarItem appearance];
    [tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:kBlackColor, NSForegroundColorAttributeName,kSystemFontSize(12),NSFontAttributeName,nil] forState:UIControlStateNormal];
    [tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:AppMainColor, NSForegroundColorAttributeName,kSystemFontSize(12),NSFontAttributeName,nil] forState:UIControlStateHighlighted];
    [tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:AppMainColor, NSForegroundColorAttributeName,kSystemFontSize(12),NSFontAttributeName,nil] forState:UIControlStateSelected];
    
    [tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -3)];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.tintColor = AppMainColor;
    self.delegate = self;//不推荐使用这种方法 这为了简单
    // Do any additional setup after loading the view.
    [self configTabBarItem];
    
#if (YiPinShangCheng == 1)//一品商城
    [self createMovableButton];
#endif
    
}


#pragma mark - 创建移动搜索按钮

#if (YiPinShangCheng == 1)//一品商城
-(void)createMovableButton{
   
    XMMovableButton *movableButton=[[XMMovableButton alloc] init];
    movableButton.frame = CGRectMake(ScreenWidth - 15 - 50, ScreenHeight - 15 - 50 - TabBarHeight, 50, 50);
    
    //点击事件
    [movableButton addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    movableButton.margin = 15;
    //圆角
    movableButton.layer.cornerRadius = 25;
    movableButton.layer.masksToBounds = YES;
    movableButton.backgroundColor = AppMainColor;
    //按钮图片
    [movableButton setImage:[UIImage imageNamed:@"customer"] forState:UIControlStateNormal];
    self.csButton = movableButton;
    [self.view addSubview:movableButton];
}

-(void)buttonClick{
    if(![EJSUserTokenModel userTokenModel]){
        EJSLoginViewController *loginVC = [[EJSLoginViewController alloc] initWithNibName:@"EJSLoginViewController" bundle:nil];
        FlyNavigationController *nav = [[FlyNavigationController alloc] initWithRootViewController:loginVC];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    CustomerServiceViewController *customerServiceVC = [CustomerServiceViewController new];
    [self.selectedViewController pushViewController:customerServiceVC animated:YES];
}


#endif

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 设置tabbaritem
- (void)configTabBarItem
{
    UITabBar *tabBar = self.tabBar;
    for (int index = 0; index < tabBar.items.count; index++)
    {
        UITabBarItem *tabBarItem = [tabBar.items objectAtIndex:index];
        tabBarItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"tabBarItem%d_normal",index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"tabBarItem%d_select",index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
}


@end
